<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<html><!-- InstanceBegin template="/Templates/common.dwt" codeOutsideHTMLIsLocked="false" -->
<!--#include virtual="/timereport/include/auth.asp" -->
<!--#include virtual="/timereport/include/common.asp" -->

<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Importa</title>
<!-- InstanceEndEditable --> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<SCRIPT language=JavaScript src= "/timereport/include/menu/menu_array.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src= "/timereport/include/menu/mmenu.js" type=text/javascript></SCRIPT>

<body>
<table width="760" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr> 
    <td height="30" class="BarraTop"><div align="right">Utente: <%= session("UserName") %> 
      </div></td>
  </tr>
  <tr>
    <td height="30">&nbsp;</td>
  </tr>
  <tr> <!-- InstanceBeginEditable name="principale" --> 
    <td > 
      <%
			Dim CS1, CS2,sCommento
			Dim count

			if request("update") <> "" Then
			
			Set CON1 = Server.CreateObject("ADODB.Connection")
	         Set CON2 = Server.CreateObject("ADODB.Connection")
			 
	         CS1         = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
			                                            "Persist Security Info=False;" &_
                                             			"Data Source=" & server.MapPath(PATH_DATABASE)  & "\timereport.mdb" & ";" & _
                                             			"Jet OLEDB:Database"
	
			CS2   = "Provider=SQLOLEDB;Data Source=" & DATASOURCE & _
		                                     ";Initial Catalog=" & DATABASE & _
											 ";uid=" & USER & _
											 ";pwd="  & PWD 
	
	        CON1.Open CS1
			CON2.Open CS2
			
			If request("elab") = 1 or request("elab") = 2 Then ' ********** 1/2
	
'		***** Tabella Spese *****
	        Set RS2 = Server.CreateObject("ADODB.Recordset")
            RS2.Open "Expenses", CON2, adOpenForwardOnly, adLockPessimistic
	
			SET RS1 = Server.CreateObject("ADODB.Recordset")
' **** cambiare la condizione di selezione per selezionare i record da copirare sul DB SQL SERVER			
           	 If request("elab") = 1  Then
		    	RS1.Open "Select * from Expenses where date <= #12-31-2004#", CON1, adOpenForwardOnly, adLockReadOnly
			else
		    	RS1.Open "Select * from Expenses where date > #12-31-2004#", CON1, adOpenForwardOnly, adLockReadOnly			
			End If
						
			count = 0
						
			while RS1.EOF <> true
				RS2.addnew
' RS2("Expenses_Id") =  RS1("Expenses_Id") chiave
				RS2("Projects_Id") =  RS1("Projects_Id")
				RS2("Persons_id") =  RS1("Persons_id")
				RS2("ExpenseType_id") =  RS1("ExpenseType_id")
				RS2("Date") =  RS1("Date")
				RS2("Amount") =  RS1("Amount")
				
				sCommento = Replace(RS1("Comment"), chr(12), "")
				sCommento = Replace(sCommento	, chr(13), "")			
				sCommento = Replace(sCommento	, chr(10), "")			
				sCommento = Replace(sCommento	, chr(9), "")
				
				RS2("Comment") =  sCommento			
				RS2("CreditCardPayed") =  RS1("CreditCardPayed")			
				RS2.update
				count = count + 1		
				RS1.movenext
			Wend	
				
			else ' **************** Carica Ore *************
			
			'		***** Tabella Spese *****
	        Set RS2 = Server.CreateObject("ADODB.Recordset")
            RS2.Open "Hours", CON2, adOpenForwardOnly, adLockPessimistic
	
			SET RS1 = Server.CreateObject("ADODB.Recordset")
' **** cambiare la condizione di selezione per selezionare i record da copirare sul DB SQL SERVER			
           	 If request("elab") = 3  Then
		    	RS1.Open "Select * from Hours where date <= #12-31-2004#", CON1, adOpenForwardOnly, adLockReadOnly
			else
		    	RS1.Open "Select * from Hours where date > #12-31-2004#", CON1, adOpenForwardOnly, adLockReadOnly			
			End If
						
			count = 0
						
			while RS1.EOF <> true
				RS2.addnew
				RS2("Projects_Id") =  RS1("Projects_Id")
				RS2("Persons_id") =  RS1("Persons_id")
				RS2("Date") =  RS1("Date")
				RS2("Hours") =  RS1("Hours")
				RS2("HourType_Id") =  RS1("HourType_Id")
				
				RS2.update
				count = count + 1		
				RS1.movenext
			Wend
			
			End if ' elab
			
  			RS1.close
			RS2.close
	  		CON1.Close
			CON2.Close	
			
			End if  ' update
  
	%>
      <form name="form1" method="post" action="import.asp">
        <p>
          <input type="radio" name="elab" value="1">
          Spese &lt; 31/12/2004</p>
        <p> 
          <input type="radio" name="elab" value="2">
          Spese &gt; 31/12/2004 </p>
        <p> 
          <input type="radio" name="elab" value="3">
          Ore &lt; 31/12/2004</p>
        <p> 
          <input type="radio" name="elab" value="4">
          Ore &gt;31/12/2004</p>
        <p>
          <input name="update" type="submit" id="update" value="Submit">
        </p>
      </form>
      <p>&nbsp;</p>
      <p><%= count %> record aggiornati</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <!-- InstanceEndEditable --></tr>
</table>
</body>
<!-- InstanceEnd --></html>
